import { appIdYellow, logoutUrl, scopeYellow } from "./auth";
import Fetch from "./request";

export const fetchUserInfo = (access_token: string) => {
  return Fetch.post(
    "https://account.cloud.huawei.com/rest.php?nsp_svc=GOpen.User.getInfo&getNickName=1",
    null,
    "application/x-www-form-urlencoded;charset=utf-8;",
    {
      Authorization: `Bearer ${access_token}`,
    }
  );
};

export const fetchUserInfoYellow = (access_token: string) => {
  return Fetch.post(
    `https://uniportal.huawei.com/sasslogin1/oauth2/userinfo?access_token=${access_token}&scope=${scopeYellow}&client_id=${appIdYellow}`,
    null,
    "application/x-www-form-urlencoded;charset=utf-8;",
    {
      Authorization: `Bearer ${access_token}`,
    }
  );
};

export const fetchLogout = (access_token: string) => {
  return Fetch.post(
    logoutUrl,
    null,
    "application/x-www-form-urlencoded;charset=utf-8;",
    {
      Authorization: `Bearer ${access_token}`,
    }
  );
};

export const fetchLogoutYellow = () => {
  return Fetch.get("http://localhost.huawei.com:5500/logout", null);
};
